<include file="Public:meta" />
<style>
.swiper-container{position:fixed;top:20px;left:0;right:0;bottom:0}
</style>
<include file="Public:cate_head" />
<div class="listpanel">
<include file="Public:category" />
    <!-- filter -->
    <div class="filter">
        <div class="filter-item"><a href="{:U("jingxuan/index",array('cid'=>$cid,'sort'=>'new'))}?k={:urldecode($sokey)}">综合</a> <empty name="txt_sort"><i class="icon-caret down"></i></empty> <if condition='$txt_sort eq "new"'><i class="icon-caret down"></i></if></div>
        <div class="filter-item"><a href="{:U("jingxuan/index",array('cid'=>$cid,'sort'=>'hot'))}?k={:urldecode($sokey)}">月销量</a><if condition='$txt_sort eq "hot"'><i class="icon-caret down"></i></if></div>
        <div class="filter-item"><a href="{:U("jingxuan/index",array('cid'=>$cid,'sort'=>'rate'))}?k={:urldecode($sokey)}">大额券</a><if condition='$txt_sort eq "rate"'><i class="icon-caret down"></i></if></div>
        <div class="filter-item">
            <a href="{:U("jingxuan/index",array('cid'=>$cid,'sort'=>'price'))}?k={:urldecode($sokey)}">券后价</a><if condition='$txt_sort eq "price"'><i class="icon-caret down"></i></if>
        </div>
    </div>
</div>
<div id="swiper" class="swiper-container">
<div id="swiperWrapper" class="swiper-wrapper">
<div id="mescroll" class="mescroll">
<ul id="dataList" class="data-list list">
	
</ul>
</div>
</div></div>

<include file="Public:footer" />
<tqkjs  href="__STATIC__/wap/js/jquery.min.js,__STATIC__/wap/js/amazeui.min.js,__STATIC__/wap/js/mescroll.min.js,__STATIC__/wap/js/swiper.min.js"/>
<script type="text/javascript">
var curNavDom;
var i=$('.active').parent().index('li');
$("#nav li").each(function(n,dom){
	if (dom.getAttribute("i")==i) {
		dom.classList.add("active");
		curNavDom=dom;
	} else{
		dom.classList.remove("active");
	}
});
var isFirst = true;
var issave=false;
var ispage=1;
var posname="pos_{$cid}";
var htname="ht_{$cid}";
var pgname="pg_{$cid}";
var pgnum = parseInt(sessionStorage.getItem(pgname));
if(pgnum>0){
var pageIndex = pgnum;		
}else{
var pageIndex = 0;	
}
page = {num:1};
var mescroll = new MeScroll("mescroll", {
	      up: {
                auto:false,
                callback: getListData,
                isBounce: false,
                hardwareClass:'mescroll-hardware',
                	warpClass: "mescroll-upwarp",
                clearEmptyId: "dataList",
                toTop:{ 
                    src : "__STATIC__/wap/images/icon/mescroll-totop.png",
                },
                onScroll:function(mescroll){
                <if condition="$isweixin">
                	if(isNaN(parseInt(sessionStorage.getItem(posname))) || issave){
                 var pos=mescroll.getScrollTop();
                 sessionStorage.setItem(posname,pos); 
                 var datahtml =$('#dataList').html();
                 sessionStorage.setItem(htname,datahtml);
                 issave = true; 
                 sessionStorage.setItem(pgname,ispage); 
                 }
                	</if>
                 
                }
            }
		});

var scrollxContent=document.getElementById("scrollxContent");
var star = scrollxContent.scrollLeft;
var end = curNavDom.offsetLeft + curNavDom.clientWidth/2 - document.body.clientWidth/2;
mescroll.getStep(star, end, function(step,timer){
scrollxContent.scrollLeft=step; 
});

	function getListData(page){
				getListDataFromNet(page.num+pageIndex,function(curPageData){
					mescroll.endByPage(20, {$page_size});
					setListData(curPageData);
				}, function(){
	                mescroll.endErr();
				});
			}
	function getListDataFromNet(pageNum,successCallback,errorCallback) {
			 var ajaxurl="{:U('jingxuan/catelist',array('cid'=>$cid,'sort'=>$txt_sort))}";
			 ajaxurl=ajaxurl+"?k={$sokey}&p="+pageNum; 
			 ispage=pageNum;
                	$.ajax({
		                type: 'GET',
		                url: ajaxurl,
		                dataType: 'html',
		                success: function(data){
		                	successCallback(data);
		                },
		                error: errorCallback
		            });
		    
			}
function setListData(curPageData){
				var listDom=document.getElementById("dataList");
				var liDom=document.createElement("li");
				liDom.innerHTML=curPageData;
				listDom.appendChild(liDom);
<if condition="$isweixin">             
 if(isFirst){ //如果存在缓存
 var tops = parseInt(sessionStorage.getItem(posname));
 var htmldata = sessionStorage.getItem(htname);
 if(htmldata){
 $('#dataList').html(htmldata);
 mescroll.scrollTo(tops,0);
 }
sessionStorage.removeItem(posname);
sessionStorage.removeItem(htname);
sessionStorage.removeItem(pgname);
sessionStorage.clear();
isFirst = false;
 }
 </if>
			}
function jumpto(quan,num_id,quanurl){
	  var num_id=num_id;
	  var quan=quan;
	  var quanurl=quanurl;
	  var trackurl='{$trackurl}';
	  $.ajax({
	  	type:"post",
	  	data:{numid:num_id,quan:quan,quanurl,quanurl},
	  	url:"{:U('jumpto/jumpclick')}",
	  	dataType: 'json',
	  	success:function(json){
	  		if(json.status==1){
	  			window.location.href=json.urls+trackurl;
	  		}
	  	}
	  });
	 }
</script>
</body>
</html>
